import sys
sys.path.extend(['.', '..'])
from c_ast_decl import ASTBuilder
builder = ASTBuilder()
ast = (builder.do_while_loop(cond=builder.expr('!=', builder.var('flag'), builder.const(0)))
          .body(
              builder.if_else(
                  cond=builder.expr('>', builder.var('counter'), builder.const(10)),
                  then_block=builder.body(
                      builder.add_break()  # 触发循环终止
                  )
              )
          )._exit_loop().build())

# 验证生成的AST结构
from pycparser import c_generator
print(ast)
print(c_generator.CGenerator().visit(ast))